﻿using Soft.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Soft.Service.Manager
{

    /// <summary>
    /// 远程服务映射执行器
    /// </summary>
    public sealed class RemoteServerMappingPerformer : BaseRemotingObject
    {
       

        /// <summary>
        /// 映射实例的名称
        /// </summary>
        public string InstanceName
        {
            get
            {
                return RemoteServerMappingPerformer._InstanceName;
            }
        }

    
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ResultData<Guid> Login(string user, string password)
        {
            if (RemoteServerMappingPerformer.Mapping != null)
            {
                return RemoteServerMappingPerformer.Mapping.MRemoteServerMappingPerformer_UserLogin(user, password);
            }
            return new ResultData<Guid>("The service has stopped.");
        }


        /// <summary>
        /// 登出会话
        /// </summary>
        /// <param name="session"></param>
        public void Logoff(Guid session)
        {
            if (RemoteServerMappingPerformer.Mapping != null)
            {
                RemoteServerMappingPerformer.Mapping.MRemoteServerMappingPerformer_UserLogoff(session);
            }
        }


        /// <summary>
        /// 获取一个负载情况最好的IP地址 
        /// </summary>
        /// <param name="functionCode"></param>
        /// <returns></returns>
        public ResultData<IP> GetServerIP(string functionCode)
        {
            if (RemoteServerMappingPerformer.Mapping != null)
            {
                return RemoteServerMappingPerformer.Mapping.MRemoteServerMappingPerformer_GetRemoteServerIP(functionCode);
            }
            return new ResultData<IP>("The service has stopped.");
        }



        /// <summary>
        /// 登录校验
        /// </summary>
        /// <param name="user"></param>
        /// <param name="session"></param>
        /// <returns></returns>

        public bool LogonVerify(string user, Guid session)
        {
            return RemoteServerMappingPerformer.Mapping != null && RemoteServerMappingPerformer.Mapping.MRemoteServerMappingPerformer_OnLogonVerify(user, session);
        }

        

        /// <summary>
        /// 服务端停止
        /// </summary>
        private const string SERVICE_STOPPED = "The service has stopped.";



        /// <summary>
        /// Mapping管理器
        /// </summary>
        public static MappingManager Mapping;



        /// <summary>
        /// 实例Mapping的名称
        /// </summary>
        internal static string _InstanceName;


    }
}
